package com.ghsc.ghxc.jsb.ui.home

import androidx.lifecycle.MutableLiveData
import com.cn.appcore.base.BaseViewModel
import com.cn.appcore.ext.executeListResponse
import com.cn.appcore.ext.executeResponse
import com.cn.appcore.http.bean.BaseListResponse
import com.cn.appcore.http.bean.BaseResponse
import com.ghsc.ghxc.jsb.api.ApiMarket
import com.ghsc.ghxc.jsb.ui.home.bean.GoodsResultData
import com.ghsc.ghxc.jsb.ui.home.bean.HomeBannerLunBoResult
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

/**
 * 项目：GuoHuaJsb
 * 包名：com.ghsc.ghxc.jsb.ui.home
 * 类名：HomeViewModel
 * 创建时间：2024/4/23 15:01
 * 创建人 @author： xiaolin
 * 描述 ：Todo...
 */
class HomeViewModel  : BaseViewModel() {

    var onTabTypeLunBoData = MutableLiveData<BaseResponse<HomeBannerLunBoResult>>()
    fun onTabTypeLunBoMethod(paras:String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onTabTypeLunBoData(paras) }
            executeResponse(
                response,
                { onTabTypeLunBoData.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }


    /** 商品列表 **/
    var onGoodsListData = MutableLiveData<BaseResponse<GoodsResultData>>()
    fun onGoodsListMethod(paras:String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onGoodsListData(paras) }
            executeResponse(
                response,
                { onGoodsListData.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }

}